home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drivers / kchamp.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  27KB  |  802 lines

  1. /***************************************************************************
  2.  
  3. Karate Champ - (c) 1984 Data East
  4.  
  5. driver by Ernesto Corvi
  6.  
  7.  
  8. Changes:
  9. (1999/11/11 Takahiro Nogi)
  10. Changed "karatedo" to "karatevs".
  11. Supported "karatedo".
  12. Corrected DIPSW settings.(kchamp/karatedo)
  13.  
  14. Currently supported sets:
  15. Karate Champ - 1 Player Version (kchamp)
  16. Karate Champ - VS Version (kchampvs)
  17. Karate Champ - 1 Player Version Japanese (karatedo)
  18. Karate Champ - VS Version Japanese (karatevs)
  19.  
  20. VS Version Info:
  21. ---------------
  22. Memory Map:
  23. Main CPU
  24. 0000-bfff ROM (encrypted)
  25. c000-cfff RAM
  26. d000-d3ff char videoram
  27. d400-d7ff color videoram
  28. d800-d8ff sprites
  29. e000-ffff ROM (encrypted)
  30.  
  31. Sound CPU
  32. 0000-5fff ROM
  33. 6000-6300 RAM
  34.  
  35. IO Ports:
  36. Main CPU
  37. INPUT  00 = Player 1 Controls - ( ACTIVE LOW )
  38. INPUT  40 = Player 2 Controls - ( ACTIVE LOW )
  39. INPUT  80 = Coins and Start Buttons - ( ACTIVE LOW )
  40. INPUT  C0 = Dip Switches - ( ACTIVE LOW )
  41. OUTPUT 00 = Screen Flip? (There isnt a cocktail switch?) UNINMPLEMENTED
  42. OUTPUT 01 = CPU Control
  43.                 bit 0 = external nmi enable
  44. OUTPUT 02 = Sound Reset
  45. OUTPUT 40 = Sound latch write
  46.  
  47. Sound CPU
  48. INPUT  01 = Sound latch read
  49. OUTPUT 00 = AY8910 #1 data write
  50. OUTPUT 01 = AY8910 #1 control write
  51. OUTPUT 02 = AY8910 #2 data write
  52. OUTPUT 03 = AY8910 #2 control write
  53. OUTPUT 04 = MSM5205 write
  54. OUTPUT 05 = CPU Control
  55.                 bit 0 = MSM5205 trigger
  56.                 bit 1 = external nmi enable
  57.  
  58. 1P Version Info:
  59. ---------------
  60. Same as VS version but with a DAC instead of a MSM5205. Also some minor
  61. IO ports and memory map changes. Dip switches differ too.
  62.  
  63. ***************************************************************************/
  64. #include "driver.h"
  65. #include "vidhrdw/generic.h"
  66. #include "cpu/z80/z80.h"
  67.  
  68.  
  69. /* from vidhrdw */
  70. extern void kchamp_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom);
  71. extern void kchamp_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  72. extern int kchampvs_vh_start(void);
  73. extern int kchamp1p_vh_start(void);
  74.  
  75.  
  76. static int nmi_enable = 0;
  77. static int sound_nmi_enable = 0;
  78.  
  79. static struct MemoryReadAddress readmem[] =
  80. {
  81.     { 0x0000, 0xbfff, MRA_ROM },
  82.     { 0xc000, 0xcfff, MRA_RAM },
  83.     { 0xd000, 0xd3ff, videoram_r },
  84.     { 0xd400, 0xd7ff, colorram_r },
  85.     { 0xd800, 0xd8ff, spriteram_r },
  86.     { 0xd900, 0xdfff, MRA_RAM },
  87.     { 0xe000, 0xffff, MRA_ROM },
  88.     { -1 }
  89. };
  90.  
  91. static struct MemoryWriteAddress writemem[] =
  92. {
  93.     { 0x0000, 0xbfff, MWA_ROM },
  94.     { 0xc000, 0xcfff, MWA_RAM },
  95.     { 0xd000, 0xd3ff, videoram_w, &videoram, &videoram_size },
  96.     { 0xd400, 0xd7ff, colorram_w, &colorram },
  97.     { 0xd800, 0xd8ff, spriteram_w, &spriteram, &spriteram_size },
  98.     { 0xd900, 0xdfff, MWA_RAM },
  99.     { 0xe000, 0xffff, MWA_ROM },
  100.     { -1 }
  101. };
  102.  
  103. static struct MemoryReadAddress sound_readmem[] =
  104. {
  105.     { 0x0000, 0x5fff, MRA_ROM },
  106.     { 0x6000, 0xffff, MRA_RAM },
  107.     { -1 }
  108. };
  109.  
  110. static struct MemoryWriteAddress sound_writemem[] =
  111. {
  112.     { 0x0000, 0x5fff, MWA_ROM },
  113.     { 0x6000, 0xffff, MWA_RAM },
  114.     { -1 }
  115. };
  116.  
  117. static WRITE_HANDLER( control_w ) {
  118.     nmi_enable = data & 1;
  119. }
  120.  
  121. static WRITE_HANDLER( sound_reset_w ) {
  122.     if ( !( data & 1 ) )
  123.         cpu_set_reset_line(1,PULSE_LINE);
  124. }
  125.  
  126. static WRITE_HANDLER( sound_control_w ) {
  127.     MSM5205_reset_w( 0, !( data & 1 ) );
  128.     sound_nmi_enable = ( ( data >> 1 ) & 1 );
  129. }
  130.  
  131. static WRITE_HANDLER( sound_command_w ) {
  132.     soundlatch_w( 0, data );
  133.     cpu_cause_interrupt( 1, 0xff );
  134. }
  135.  
  136. static int msm_data = 0;
  137. static int msm_play_lo_nibble = 1;
  138.  
  139. static WRITE_HANDLER( sound_msm_w ) {
  140.     msm_data = data;
  141.     msm_play_lo_nibble = 1;
  142. }
  143.  
  144. static struct IOReadPort readport[] =
  145. {
  146.     { 0x00, 0x00, input_port_0_r }, /* Player 1 controls - ACTIVE LOW */
  147.     { 0x40, 0x40, input_port_1_r }, /* Player 2 controls - ACTIVE LOW */
  148.     { 0x80, 0x80, input_port_2_r }, /* Coins & Start - ACTIVE LOW */
  149.     { 0xC0, 0xC0, input_port_3_r }, /* Dipswitch */
  150.     { -1 }    /* end of table */
  151. };
  152.  
  153. static struct IOWritePort writeport[] =
  154. {
  155.     { 0x00, 0x00, MWA_NOP },
  156.     { 0x01, 0x01, control_w },
  157.     { 0x02, 0x02, sound_reset_w },
  158.     { 0x40, 0x40, sound_command_w },
  159.     { -1 }    /* end of table */
  160. };
  161.  
  162. static struct IOReadPort sound_readport[] =
  163. {
  164.     { 0x01, 0x01, soundlatch_r },
  165.     { -1 }    /* end of table */
  166. };
  167.  
  168. static struct IOWritePort sound_writeport[] =
  169. {
  170.     { 0x00, 0x00, AY8910_write_port_0_w },
  171.     { 0x01, 0x01, AY8910_control_port_0_w },
  172.     { 0x02, 0x02, AY8910_write_port_1_w },
  173.     { 0x03, 0x03, AY8910_control_port_1_w },
  174.     { 0x04, 0x04, sound_msm_w },
  175.     { 0x05, 0x05, sound_control_w },
  176.     { -1 }    /* end of table */
  177. };
  178.  
  179. /********************
  180. * 1 Player Version  *
  181. ********************/
  182.  
  183. static struct MemoryReadAddress kc_readmem[] =
  184. {
  185.     { 0x0000, 0xbfff, MRA_ROM },
  186.     { 0xc000, 0xdfff, MRA_RAM },
  187.     { 0xe000, 0xe3ff, videoram_r },
  188.     { 0xe400, 0xe7ff, colorram_r },
  189.     { 0xea00, 0xeaff, spriteram_r },
  190.     { 0xeb00, 0xffff, MRA_RAM },
  191.     { -1 }
  192. };
  193.  
  194. static struct MemoryWriteAddress kc_writemem[] =
  195. {
  196.     { 0x0000, 0xbfff, MWA_ROM },
  197.     { 0xc000, 0xdfff, MWA_RAM },
  198.     { 0xe000, 0xe3ff, videoram_w, &videoram, &videoram_size },
  199.     { 0xe400, 0xe7ff, colorram_w, &colorram },
  200.     { 0xea00, 0xeaff, spriteram_w, &spriteram, &spriteram_size },
  201.     { 0xeb00, 0xffff, MWA_RAM },
  202.     { -1 }
  203. };
  204.  
  205. static struct MemoryReadAddress kc_sound_readmem[] =
  206. {
  207.     { 0x0000, 0xdfff, MRA_ROM },
  208.     { 0xe000, 0xe2ff, MRA_RAM },
  209.     { -1 }
  210. };
  211.  
  212. static struct MemoryWriteAddress kc_sound_writemem[] =
  213. {
  214.     { 0x0000, 0xdfff, MWA_ROM },
  215.     { 0xe000, 0xe2ff, MWA_RAM },
  216.     { -1 }
  217. };
  218.  
  219. static READ_HANDLER( sound_reset_r ) {
  220.     cpu_set_reset_line(1,PULSE_LINE);
  221.     return 0;
  222. }
  223.  
  224. static WRITE_HANDLER( kc_sound_control_w ) {
  225.     if ( offset == 0 )
  226.         sound_nmi_enable = ( ( data >> 7 ) & 1 );
  227. //    else
  228. //        DAC_set_volume(0,( data == 1 ) ? 255 : 0,0);
  229. }
  230.  
  231. static struct IOReadPort kc_readport[] =
  232. {
  233.     { 0x90, 0x90, input_port_0_r }, /* Player 1 controls - ACTIVE LOW */
  234.     { 0x98, 0x98, input_port_1_r }, /* Player 2 controls - ACTIVE LOW */
  235.     { 0xa0, 0xa0, input_port_2_r }, /* Coins & Start - ACTIVE LOW */
  236.     { 0x80, 0x80, input_port_3_r }, /* Dipswitch */
  237.     { 0xa8, 0xa8, sound_reset_r },
  238.     { -1 }    /* end of table */
  239. };
  240.  
  241. static struct IOWritePort kc_writeport[] =
  242. {
  243.     { 0x80, 0x80, MWA_NOP },
  244.     { 0x81, 0x81, control_w },
  245.     { 0xa8, 0xa8, sound_command_w },
  246.     { -1 }    /* end of table */
  247. };
  248.  
  249. static struct IOReadPort kc_sound_readport[] =
  250. {
  251.     { 0x06, 0x06, soundlatch_r },
  252.     { -1 }    /* end of table */
  253. };
  254.  
  255. static struct IOWritePort kc_sound_writeport[] =
  256. {
  257.     { 0x00, 0x00, AY8910_write_port_0_w },
  258.     { 0x01, 0x01, AY8910_control_port_0_w },
  259.     { 0x02, 0x02, AY8910_write_port_1_w },
  260.     { 0x03, 0x03, AY8910_control_port_1_w },
  261.     { 0x04, 0x04, DAC_0_data_w },
  262.     { 0x05, 0x05, kc_sound_control_w },
  263.     { -1 }    /* end of table */
  264. };
  265.  
  266.  
  267. INPUT_PORTS_START( kchampvs )
  268.     PORT_START    /* IN0 */
  269.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_RIGHT | IPF_4WAY )
  270.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_LEFT | IPF_4WAY )
  271.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_UP | IPF_4WAY )
  272.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_DOWN | IPF_4WAY )
  273.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_RIGHT | IPF_4WAY )
  274.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_LEFT | IPF_4WAY )
  275.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_UP | IPF_4WAY )
  276.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_DOWN | IPF_4WAY )
  277.  
  278.     PORT_START    /* IN1 */
  279.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_RIGHT | IPF_PLAYER2 | IPF_4WAY )
  280.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_LEFT | IPF_PLAYER2 | IPF_4WAY )
  281.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_UP | IPF_PLAYER2 | IPF_4WAY )
  282.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_DOWN | IPF_PLAYER2 | IPF_4WAY )
  283.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_RIGHT | IPF_PLAYER2 | IPF_4WAY )
  284.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_LEFT | IPF_PLAYER2 | IPF_4WAY )
  285.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_UP | IPF_PLAYER2 | IPF_4WAY )
  286.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_DOWN | IPF_PLAYER2 | IPF_4WAY )
  287.  
  288.     PORT_START    /* IN2 */
  289.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
  290.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )
  291.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_START1 )
  292.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START2 )
  293.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNUSED )
  294.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
  295.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNUSED )
  296.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
  297.  
  298.     PORT_START    /* DSW0 */
  299.     PORT_DIPNAME( 0x03, 0x03, DEF_STR( Coin_B ) )
  300.     PORT_DIPSETTING(    0x00, DEF_STR( 3C_1C ) )
  301.     PORT_DIPSETTING(    0x01, DEF_STR( 2C_1C ) )
  302.     PORT_DIPSETTING(    0x03, DEF_STR( 1C_1C ) )
  303.     PORT_DIPSETTING(    0x02, DEF_STR( 1C_2C ) )
  304.     PORT_DIPNAME( 0x0c, 0x0c, DEF_STR( Coin_A ) )
  305.     PORT_DIPSETTING(    0x00, DEF_STR( 3C_1C ) )
  306.     PORT_DIPSETTING(    0x04, DEF_STR( 2C_1C ) )
  307.     PORT_DIPSETTING(    0x0c, DEF_STR( 1C_1C ) )
  308.     PORT_DIPSETTING(    0x08, DEF_STR( 1C_2C ) )
  309.     PORT_DIPNAME( 0x30, 0x10, DEF_STR( Difficulty ) )
  310.     PORT_DIPSETTING(    0x30, "Easy" )
  311.     PORT_DIPSETTING(    0x20, "Medium" )
  312.     PORT_DIPSETTING(    0x10, "Hard" )
  313.     PORT_DIPSETTING(    0x00, "Hardest" )
  314.     PORT_DIPNAME( 0x40, 0x00, DEF_STR( Demo_Sounds ) )
  315.     PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
  316.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  317.     PORT_DIPNAME( 0x80, 0x80, DEF_STR( Free_Play ) )
  318.     PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
  319.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  320. INPUT_PORTS_END
  321.  
  322.  
  323. /********************
  324. * 1 Player Version  *
  325. ********************/
  326.  
  327. INPUT_PORTS_START( kchamp )
  328.     PORT_START    /* IN0 */
  329.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_RIGHT | IPF_4WAY )
  330.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_LEFT | IPF_4WAY )
  331.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_UP | IPF_4WAY )
  332.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_DOWN | IPF_4WAY )
  333.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_RIGHT | IPF_4WAY )
  334.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_LEFT | IPF_4WAY )
  335.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_UP | IPF_4WAY )
  336.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_DOWN | IPF_4WAY )
  337.  
  338.     PORT_START    /* IN1 */
  339.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_RIGHT | IPF_PLAYER2 | IPF_4WAY )
  340.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_LEFT | IPF_PLAYER2 | IPF_4WAY )
  341.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_UP | IPF_PLAYER2 | IPF_4WAY )
  342.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_DOWN | IPF_PLAYER2 | IPF_4WAY )
  343.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_RIGHT | IPF_PLAYER2 | IPF_4WAY )
  344.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_LEFT | IPF_PLAYER2 | IPF_4WAY )
  345.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_UP | IPF_PLAYER2 | IPF_4WAY )
  346.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_DOWN | IPF_PLAYER2 | IPF_4WAY )
  347.  
  348.     PORT_START    /* IN2 */
  349.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
  350.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )
  351.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_START1 )
  352.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START2 )
  353.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNUSED )
  354.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
  355.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNUSED )
  356.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
  357.  
  358.     PORT_START    /* DSW0 */
  359.     PORT_DIPNAME( 0x03, 0x03, DEF_STR( Coin_B ) )
  360.     PORT_DIPSETTING(    0x00, DEF_STR( 3C_1C ) )
  361.     PORT_DIPSETTING(    0x01, DEF_STR( 2C_1C ) )
  362.     PORT_DIPSETTING(    0x03, DEF_STR( 1C_1C ) )
  363.     PORT_DIPSETTING(    0x02, DEF_STR( 1C_2C ) )
  364.     PORT_DIPNAME( 0x0c, 0x0c, DEF_STR( Coin_A ) )
  365.     PORT_DIPSETTING(    0x00, DEF_STR( 3C_1C ) )
  366.     PORT_DIPSETTING(    0x04, DEF_STR( 2C_1C ) )
  367.     PORT_DIPSETTING(    0x0c, DEF_STR( 1C_1C ) )
  368.     PORT_DIPSETTING(    0x08, DEF_STR( 1C_2C ) )
  369.     PORT_DIPNAME( 0x10, 0x10, DEF_STR( Difficulty ) )
  370.     PORT_DIPSETTING(    0x00, "Hard" )
  371.     PORT_DIPSETTING(    0x10, "Normal" )
  372.     PORT_DIPNAME( 0x20, 0x20, DEF_STR( Free_Play ) )
  373.     PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
  374.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  375.     PORT_DIPNAME( 0x40, 0x00, DEF_STR( Demo_Sounds ) )
  376.     PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
  377.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  378.     PORT_DIPNAME( 0x80, 0x00, DEF_STR( Cabinet ) )
  379.     PORT_DIPSETTING(    0x00, DEF_STR( Upright ) )
  380.     PORT_DIPSETTING(    0x80, DEF_STR( Cocktail ) )
  381. INPUT_PORTS_END
  382.  
  383. static struct GfxLayout tilelayout =
  384. {
  385.     8,8,    /* tile size */
  386.     256*8,    /* number of tiles */
  387.     2,    /* bits per pixel */
  388.     { 0x4000*8, 0 }, /* plane offsets */
  389.     { 0,1,2,3,4,5,6,7 }, /* x offsets */
  390.     { 0*8,1*8,2*8,3*8,4*8,5*8,6*8,7*8 }, /* y offsets */
  391.     8*8    /* offset to next tile */
  392. };
  393.  
  394. static struct GfxLayout spritelayout =
  395. {
  396.     16,16,    /* tile size */
  397.     512,    /* number of tiles */
  398.     2,    /* bits per pixel */
  399.     { 0xC000*8, 0 }, /* plane offsets */
  400.     { 0,1,2,3,4,5,6,7,
  401.         0x2000*8+0,0x2000*8+1,0x2000*8+2,0x2000*8+3,
  402.         0x2000*8+4,0x2000*8+5,0x2000*8+6,0x2000*8+7 }, /* x offsets */
  403.     { 0*8,1*8,2*8,3*8,4*8,5*8,6*8,7*8,
  404.     8*8,9*8,10*8,11*8,12*8,13*8,14*8, 15*8 }, /* y offsets */
  405.     16*8    /* ofset to next tile */
  406. };
  407.  
  408. static struct GfxDecodeInfo gfxdecodeinfo[] =
  409. {
  410.     { REGION_GFX1, 0x00000, &tilelayout,    32*4, 32 },
  411.     { REGION_GFX2, 0x08000, &spritelayout,    0, 16 },
  412.     { REGION_GFX2, 0x04000, &spritelayout,    0, 16 },
  413.     { REGION_GFX2, 0x00000, &spritelayout,    0, 16 },
  414.     { -1 }
  415. };
  416.  
  417.  
  418.  
  419. static int kc_interrupt( void ) {
  420.  
  421.     if ( nmi_enable )
  422.         return Z80_NMI_INT;
  423.  
  424.     return Z80_IGNORE_INT;
  425. }
  426.  
  427. static void msmint( int data ) {
  428.  
  429.     static int counter = 0;
  430.  
  431.     if ( msm_play_lo_nibble )
  432.         MSM5205_data_w( 0, msm_data & 0x0f );
  433.     else
  434.         MSM5205_data_w( 0, ( msm_data >> 4 ) & 0x0f );
  435.  
  436.     msm_play_lo_nibble ^= 1;
  437.  
  438.     if ( !( counter ^= 1 ) ) {
  439.         if ( sound_nmi_enable ) {
  440.             cpu_cause_interrupt( 1, Z80_NMI_INT );
  441.         }
  442.     }
  443. }
  444.  
  445. static struct AY8910interface ay8910_interface =
  446. {
  447.     2, /* 2 chips */
  448.     1500000,            /* 12 Mhz / 8 = 1.5 Mhz */
  449.     { 30, 30 },            // Modified by T.Nogi 1999/11/08
  450.     { 0 },
  451.     { 0 },
  452.     { 0 },
  453.     { 0 }
  454. };
  455.  
  456. static struct MSM5205interface msm_interface =
  457. {
  458.     1,                /* 1 chip */
  459.     375000,                /* 12Mhz / 16 / 2 */
  460.     { msmint },            /* interrupt function */
  461.     { MSM5205_S96_4B },        /* 1 / 96 = 3906.25Hz playback */
  462.     { 100 }
  463. };
  464.  
  465. /********************
  466. * 1 Player Version  *
  467. ********************/
  468.  
  469. static int sound_int( void ) {
  470.  
  471.     if ( sound_nmi_enable )
  472.         return Z80_NMI_INT;
  473.  
  474.     return Z80_IGNORE_INT;
  475. }
  476.  
  477. static struct DACinterface dac_interface =
  478. {
  479.     1,
  480.     { 50 }
  481. };
  482.  
  483.  
  484. static struct MachineDriver machine_driver_kchampvs =
  485. {
  486.     /* basic machine hardware */
  487.     {
  488.         {
  489.             CPU_Z80,
  490.             3000000,    /* 12Mhz / 4 = 3.0 Mhz */
  491.             readmem,writemem,readport,writeport,
  492.             kc_interrupt,1
  493.         },
  494.         {
  495.             CPU_Z80 | CPU_AUDIO_CPU,
  496.             3000000,    /* 12Mhz / 4 = 3.0 Mhz */
  497.             sound_readmem,sound_writemem,sound_readport,sound_writeport,
  498.             ignore_interrupt, 0
  499.             /* irq's triggered from main cpu */
  500.             /* nmi's from msm5205 */
  501.         }
  502.     },
  503.     60,DEFAULT_60HZ_VBLANK_DURATION,
  504.     1,    /* Interleaving forced by interrupts */
  505.     0,    /* init machine */
  506.  
  507.     /* video hardware */
  508.     32*8, 32*8, { 0, 32*8-1, 2*8, 30*8-1 },
  509.     gfxdecodeinfo,
  510.     256, /* number of colors */
  511.     256, /* color table length */
  512.     kchamp_vh_convert_color_prom,
  513.  
  514.     VIDEO_TYPE_RASTER | VIDEO_SUPPORTS_DIRTY,
  515.     0,
  516.     kchampvs_vh_start,
  517.     generic_vh_stop,
  518.     kchamp_vh_screenrefresh,
  519.  
  520.     /* sound hardware */
  521.     0,0,0,0,
  522.     {
  523.         {
  524.             SOUND_AY8910,
  525.             &ay8910_interface
  526.         },
  527.         {
  528.             SOUND_MSM5205,
  529.             &msm_interface
  530.         }
  531.     }
  532. };
  533.  
  534. /********************
  535. * 1 Player Version  *
  536. ********************/
  537.  
  538. static struct MachineDriver machine_driver_kchamp =
  539. {
  540.     /* basic machine hardware */
  541.     {
  542.         {
  543.             CPU_Z80,
  544.             3000000,    /* 12Mhz / 4 = 3.0 Mhz */
  545.             kc_readmem, kc_writemem, kc_readport, kc_writeport,
  546.             kc_interrupt,1
  547.         },
  548.         {
  549.             CPU_Z80 | CPU_AUDIO_CPU,
  550.             3000000,    /* 12Mhz / 4 = 3.0 Mhz */
  551.             kc_sound_readmem,kc_sound_writemem,kc_sound_readport,kc_sound_writeport,
  552.             ignore_interrupt, 0,
  553.             sound_int, 125 /* Hz */
  554.             /* irq's triggered from main cpu */
  555.             /* nmi's from 125 Hz clock */
  556.         }
  557.     },
  558.     60,DEFAULT_60HZ_VBLANK_DURATION,
  559.     1,    /* Interleaving forced by interrupts */
  560.     0,    /* init machine */
  561.  
  562.     /* video hardware */
  563.     32*8, 32*8, { 0, 32*8-1, 2*8, 30*8-1 },
  564.     gfxdecodeinfo,
  565.     256, /* number of colors */
  566.     256, /* color table length */
  567.     kchamp_vh_convert_color_prom,
  568.  
  569.     VIDEO_TYPE_RASTER | VIDEO_SUPPORTS_DIRTY,
  570.     0,
  571.     kchamp1p_vh_start,
  572.     generic_vh_stop,
  573.     kchamp_vh_screenrefresh,
  574.  
  575.     /* sound hardware */
  576.     0,0,0,0,
  577.     {
  578.         {
  579.             SOUND_AY8910,
  580.             &ay8910_interface
  581.         },
  582.         {
  583.             SOUND_DAC,
  584.             &dac_interface
  585.         }
  586.     }
  587. };
  588.  
  589.  
  590. /***************************************************************************
  591.  
  592.   Game driver(s)
  593.  
  594. ***************************************************************************/
  595.  
  596. ROM_START( kchamp )
  597.     ROM_REGION( 0x10000, REGION_CPU1 )    /* 64k for code */
  598.     ROM_LOAD( "b014.bin", 0x0000, 0x2000, 0x0000d1a0 )
  599.     ROM_LOAD( "b015.bin", 0x2000, 0x2000, 0x03fae67e )
  600.     ROM_LOAD( "b016.bin", 0x4000, 0x2000, 0x3b6e1d08 )
  601.     ROM_LOAD( "b017.bin", 0x6000, 0x2000, 0xc1848d1a )
  602.     ROM_LOAD( "b018.bin", 0x8000, 0x2000, 0xb824abc7 )
  603.     ROM_LOAD( "b019.bin", 0xa000, 0x2000, 0x3b487a46 )
  604.  
  605.     ROM_REGION( 0x10000, REGION_CPU2 ) /* Sound CPU */ /* 64k for code */
  606.     ROM_LOAD( "b026.bin", 0x0000, 0x2000, 0x999ed2c7 )
  607.     ROM_LOAD( "b025.bin", 0x2000, 0x2000, 0x33171e07 ) /* adpcm */
  608.     ROM_LOAD( "b024.bin", 0x4000, 0x2000, 0x910b48b9 ) /* adpcm */
  609.     ROM_LOAD( "b023.bin", 0x6000, 0x2000, 0x47f66aac )
  610.     ROM_LOAD( "b022.bin", 0x8000, 0x2000, 0x5928e749 )
  611.     ROM_LOAD( "b021.bin", 0xa000, 0x2000, 0xca17e3ba )
  612.     ROM_LOAD( "b020.bin", 0xc000, 0x2000, 0xada4f2cd )
  613.  
  614.     ROM_REGION( 0x08000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  615.     ROM_LOAD( "b000.bin", 0x00000, 0x2000, 0xa4fa98a1 )  /* plane0 */ /* tiles */
  616.     ROM_LOAD( "b001.bin", 0x04000, 0x2000, 0xfea09f7c )  /* plane1 */ /* tiles */
  617.  
  618.     ROM_REGION( 0x18000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  619.     ROM_LOAD( "b013.bin", 0x00000, 0x2000, 0xeaad4168 )  /* top, plane0 */ /* sprites */
  620.     ROM_LOAD( "b004.bin", 0x02000, 0x2000, 0x10a47e2d )  /* bot, plane0 */ /* sprites */
  621.     ROM_LOAD( "b012.bin", 0x04000, 0x2000, 0xb4842ea9 )  /* top, plane0 */ /* sprites */
  622.     ROM_LOAD( "b003.bin", 0x06000, 0x2000, 0x8cd166a5 )  /* bot, plane0 */ /* sprites */
  623.     ROM_LOAD( "b011.bin", 0x08000, 0x2000, 0x4cbd3aa3 )  /* top, plane0 */ /* sprites */
  624.     ROM_LOAD( "b002.bin", 0x0a000, 0x2000, 0x6be342a6 )  /* bot, plane0 */ /* sprites */
  625.     ROM_LOAD( "b007.bin", 0x0c000, 0x2000, 0xcb91d16b )  /* top, plane1 */ /* sprites */
  626.     ROM_LOAD( "b010.bin", 0x0e000, 0x2000, 0x489c9c04 )  /* bot, plane1 */ /* sprites */
  627.     ROM_LOAD( "b006.bin", 0x10000, 0x2000, 0x7346db8a )  /* top, plane1 */ /* sprites */
  628.     ROM_LOAD( "b009.bin", 0x12000, 0x2000, 0xb78714fc )  /* bot, plane1 */ /* sprites */
  629.     ROM_LOAD( "b005.bin", 0x14000, 0x2000, 0xb2557102 )  /* top, plane1 */ /* sprites */
  630.     ROM_LOAD( "b008.bin", 0x16000, 0x2000, 0xc85aba0e )  /* bot, plane1 */ /* sprites */
  631.  
  632.     ROM_REGION( 0x0300, REGION_PROMS )
  633.     ROM_LOAD( "br27", 0x0000, 0x0100, 0xf683c54a ) /* red */
  634.     ROM_LOAD( "br26", 0x0100, 0x0100, 0x3ddbb6c4 ) /* green */
  635.     ROM_LOAD( "br25", 0x0200, 0x0100, 0xba4a5651 ) /* blue */
  636. ROM_END
  637.  
  638. ROM_START( karatedo )
  639.     ROM_REGION( 0x10000, REGION_CPU1 )    /* 64k for code */
  640.     ROM_LOAD( "be14", 0x0000, 0x2000, 0x44e60aa0 )
  641.     ROM_LOAD( "be15", 0x2000, 0x2000, 0xa65e3793 )
  642.     ROM_LOAD( "be16", 0x4000, 0x2000, 0x151d8872 )
  643.     ROM_LOAD( "be17", 0x6000, 0x2000, 0x8f393b6a )
  644.     ROM_LOAD( "be18", 0x8000, 0x2000, 0xa09046ad )
  645.     ROM_LOAD( "be19", 0xa000, 0x2000, 0x0cdc4da9 )
  646.  
  647.     ROM_REGION( 0x10000, REGION_CPU2 ) /* Sound CPU */ /* 64k for code */
  648.     ROM_LOAD( "be26", 0x0000, 0x2000, 0x999ab0a3 )
  649.     ROM_LOAD( "be25", 0x2000, 0x2000, 0x253bf0da ) /* adpcm */
  650.     ROM_LOAD( "be24", 0x4000, 0x2000, 0xe2c188af ) /* adpcm */
  651.     ROM_LOAD( "be23", 0x6000, 0x2000, 0x25262de1 )
  652.     ROM_LOAD( "be22", 0x8000, 0x2000, 0x38055c48 )
  653.     ROM_LOAD( "be21", 0xa000, 0x2000, 0x5f0efbe7 )
  654.     ROM_LOAD( "be20", 0xc000, 0x2000, 0xcbe8a533 )
  655.  
  656.     ROM_REGION( 0x08000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  657.     ROM_LOAD( "be00",     0x00000, 0x2000, 0xcec020f2 )  /* plane0 */ /* tiles */
  658.     ROM_LOAD( "be01",     0x04000, 0x2000, 0xcd96271c )  /* plane1 */ /* tiles */
  659.  
  660.     ROM_REGION( 0x18000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  661.     ROM_LOAD( "be13",     0x00000, 0x2000, 0xfb358707 )  /* top, plane0 */ /* sprites */
  662.     ROM_LOAD( "be04",     0x02000, 0x2000, 0x48372bf8 )  /* bot, plane0 */ /* sprites */
  663.     ROM_LOAD( "b012.bin", 0x04000, 0x2000, 0xb4842ea9 )  /* top, plane0 */ /* sprites */
  664.     ROM_LOAD( "b003.bin", 0x06000, 0x2000, 0x8cd166a5 )  /* bot, plane0 */ /* sprites */
  665.     ROM_LOAD( "b011.bin", 0x08000, 0x2000, 0x4cbd3aa3 )  /* top, plane0 */ /* sprites */
  666.     ROM_LOAD( "b002.bin", 0x0a000, 0x2000, 0x6be342a6 )  /* bot, plane0 */ /* sprites */
  667.     ROM_LOAD( "be07",     0x0c000, 0x2000, 0x40f2b6fb )  /* top, plane1 */ /* sprites */
  668.     ROM_LOAD( "be10",     0x0e000, 0x2000, 0x325c0a97 )  /* bot, plane1 */ /* sprites */
  669.     ROM_LOAD( "b006.bin", 0x10000, 0x2000, 0x7346db8a )  /* top, plane1 */ /* sprites */
  670.     ROM_LOAD( "b009.bin", 0x12000, 0x2000, 0xb78714fc )  /* bot, plane1 */ /* sprites */
  671.     ROM_LOAD( "b005.bin", 0x14000, 0x2000, 0xb2557102 )  /* top, plane1 */ /* sprites */
  672.     ROM_LOAD( "b008.bin", 0x16000, 0x2000, 0xc85aba0e )  /* bot, plane1 */ /* sprites */
  673.  
  674.     ROM_REGION( 0x0300, REGION_PROMS )
  675.     ROM_LOAD( "br27", 0x0000, 0x0100, 0xf683c54a ) /* red */
  676.     ROM_LOAD( "br26", 0x0100, 0x0100, 0x3ddbb6c4 ) /* green */
  677.     ROM_LOAD( "br25", 0x0200, 0x0100, 0xba4a5651 ) /* blue */
  678. ROM_END
  679.  
  680. ROM_START( kchampvs )
  681.     ROM_REGION( 2*0x10000, REGION_CPU1 )    /* 64k for code + 64k for decrypted opcodes */
  682.     ROM_LOAD( "bs24", 0x0000, 0x2000, 0x829da69b )
  683.     ROM_LOAD( "bs23", 0x2000, 0x2000, 0x091f810e )
  684.     ROM_LOAD( "bs22", 0x4000, 0x2000, 0xd4df2a52 )
  685.     ROM_LOAD( "bs21", 0x6000, 0x2000, 0x3d4ef0da )
  686.     ROM_LOAD( "bs20", 0x8000, 0x2000, 0x623a467b )
  687.     ROM_LOAD( "bs19", 0xa000, 0x2000, 0x43e196c4 )
  688.     ROM_CONTINUE(     0xe000, 0x2000 )
  689.  
  690.     ROM_REGION( 0x10000, REGION_CPU2 ) /* Sound CPU */ /* 64k for code */
  691.     ROM_LOAD( "bs18", 0x0000, 0x2000, 0xeaa646eb )
  692.     ROM_LOAD( "bs17", 0x2000, 0x2000, 0xd71031ad ) /* adpcm */
  693.     ROM_LOAD( "bs16", 0x4000, 0x2000, 0x6f811c43 ) /* adpcm */
  694.  
  695.     ROM_REGION( 0x08000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  696.     ROM_LOAD( "bs12",     0x00000, 0x2000, 0x4c574ecd )
  697.     ROM_LOAD( "bs13",     0x02000, 0x2000, 0x750b66af )
  698.     ROM_LOAD( "bs14",     0x04000, 0x2000, 0x9ad6227c )
  699.     ROM_LOAD( "bs15",     0x06000, 0x2000, 0x3b6d5de5 )
  700.  
  701.     ROM_REGION( 0x18000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  702.     ROM_LOAD( "bs00",     0x00000, 0x2000, 0x51eda56c )
  703.     ROM_LOAD( "bs06",     0x02000, 0x2000, 0x593264cf )
  704.     ROM_LOAD( "b012.bin", 0x04000, 0x2000, 0xb4842ea9 )  /* bs01 */
  705.     ROM_LOAD( "b003.bin", 0x06000, 0x2000, 0x8cd166a5 )  /* bs07 */
  706.     ROM_LOAD( "b011.bin", 0x08000, 0x2000, 0x4cbd3aa3 )  /* bs02 */
  707.     ROM_LOAD( "b002.bin", 0x0a000, 0x2000, 0x6be342a6 )  /* bs08 */
  708.     ROM_LOAD( "bs03",     0x0c000, 0x2000, 0x8dcd271a )
  709.     ROM_LOAD( "bs09",     0x0e000, 0x2000, 0x4ee1dba7 )
  710.     ROM_LOAD( "b006.bin", 0x10000, 0x2000, 0x7346db8a )  /* bs04 */
  711.     ROM_LOAD( "b009.bin", 0x12000, 0x2000, 0xb78714fc )  /* bs10 */
  712.     ROM_LOAD( "b005.bin", 0x14000, 0x2000, 0xb2557102 )  /* bs05 */
  713.     ROM_LOAD( "b008.bin", 0x16000, 0x2000, 0xc85aba0e )  /* bs11 */
  714.  
  715.     ROM_REGION( 0x0300, REGION_PROMS )
  716.     ROM_LOAD( "br27", 0x0000, 0x0100, 0xf683c54a ) /* red */
  717.     ROM_LOAD( "br26", 0x0100, 0x0100, 0x3ddbb6c4 ) /* green */
  718.     ROM_LOAD( "br25", 0x0200, 0x0100, 0xba4a5651 ) /* blue */
  719. ROM_END
  720.  
  721. ROM_START( karatevs )
  722.     ROM_REGION( 2*0x10000, REGION_CPU1 )    /* 64k for code + 64k for decrypted opcodes */
  723.     ROM_LOAD( "br24", 0x0000, 0x2000, 0xea9cda49 )
  724.     ROM_LOAD( "br23", 0x2000, 0x2000, 0x46074489 )
  725.     ROM_LOAD( "br22", 0x4000, 0x2000, 0x294f67ba )
  726.     ROM_LOAD( "br21", 0x6000, 0x2000, 0x934ea874 )
  727.     ROM_LOAD( "br20", 0x8000, 0x2000, 0x97d7816a )
  728.     ROM_LOAD( "br19", 0xa000, 0x2000, 0xdd2239d2 )
  729.     ROM_CONTINUE(     0xe000, 0x2000 )
  730.  
  731.     ROM_REGION( 0x10000, REGION_CPU2 ) /* Sound CPU */ /* 64k for code */
  732.     ROM_LOAD( "br18", 0x0000, 0x2000, 0x00ccb8ea )
  733.     ROM_LOAD( "bs17", 0x2000, 0x2000, 0xd71031ad ) /* adpcm */
  734.     ROM_LOAD( "br16", 0x4000, 0x2000, 0x2512d961 ) /* adpcm */
  735.  
  736.     ROM_REGION( 0x08000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  737.     ROM_LOAD( "br12",     0x00000, 0x2000, 0x9ed6f00d )
  738.     ROM_LOAD( "bs13",     0x02000, 0x2000, 0x750b66af )
  739.     ROM_LOAD( "br14",     0x04000, 0x2000, 0xfc399229 )
  740.     ROM_LOAD( "bs15",     0x06000, 0x2000, 0x3b6d5de5 )
  741.  
  742.     ROM_REGION( 0x18000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  743.     ROM_LOAD( "br00",     0x00000, 0x2000, 0xc46a8b88 )
  744.     ROM_LOAD( "br06",     0x02000, 0x2000, 0xcf8982ff )
  745.     ROM_LOAD( "b012.bin", 0x04000, 0x2000, 0xb4842ea9 )  /* bs01 */
  746.     ROM_LOAD( "b003.bin", 0x06000, 0x2000, 0x8cd166a5 )  /* bs07 */
  747.     ROM_LOAD( "b011.bin", 0x08000, 0x2000, 0x4cbd3aa3 )  /* bs02 */
  748.     ROM_LOAD( "b002.bin", 0x0a000, 0x2000, 0x6be342a6 )  /* bs08 */
  749.     ROM_LOAD( "br03",     0x0c000, 0x2000, 0xbde8a52b )
  750.     ROM_LOAD( "br09",     0x0e000, 0x2000, 0xe9a5f945 )
  751.     ROM_LOAD( "b006.bin", 0x10000, 0x2000, 0x7346db8a )  /* bs04 */
  752.     ROM_LOAD( "b009.bin", 0x12000, 0x2000, 0xb78714fc )  /* bs10 */
  753.     ROM_LOAD( "b005.bin", 0x14000, 0x2000, 0xb2557102 )  /* bs05 */
  754.     ROM_LOAD( "b008.bin", 0x16000, 0x2000, 0xc85aba0e )  /* bs11 */
  755.  
  756.     ROM_REGION( 0x0300, REGION_PROMS )
  757.     ROM_LOAD( "br27", 0x0000, 0x0100, 0xf683c54a ) /* red */
  758.     ROM_LOAD( "br26", 0x0100, 0x0100, 0x3ddbb6c4 ) /* green */
  759.     ROM_LOAD( "br25", 0x0200, 0x0100, 0xba4a5651 ) /* blue */
  760. ROM_END
  761.  
  762.  
  763.  
  764. static void init_kchampvs( void )
  765. {
  766.     unsigned char *rom = memory_region(REGION_CPU1);
  767.     int diff = memory_region_length(REGION_CPU1) / 2;
  768.     int A;
  769.  
  770.  
  771.     memory_set_opcode_base(0,rom+diff);
  772.  
  773.     for (A = 0;A < 0x10000;A++)
  774.         rom[A+diff] = (rom[A] & 0x55) | ((rom[A] & 0x88) >> 2) | ((rom[A] & 0x22) << 2);
  775.  
  776.     /*
  777.         Note that the first 4 opcodes that the program
  778.         executes aren't encrypted for some obscure reason.
  779.         The address for the 2nd opcode (a jump) is encrypted too.
  780.         It's not clear what the 3rd and 4th opcode are supposed to do,
  781.         they just write to a RAM location. This write might be what
  782.         turns the encryption on, but this doesn't explain the
  783.         encrypted address for the jump.
  784.      */
  785.     rom[0+diff] = rom[0];    /* this is a jump */
  786.     A = rom[1] + 256 * rom[2];
  787.     rom[A+diff] = rom[A];    /* fix opcode on first jump address (again, a jump) */
  788.     rom[A+1] ^= 0xee;        /* fix address of the second jump */
  789.     A = rom[A+1] + 256 * rom[A+2];
  790.     rom[A+diff] = rom[A];    /* fix third opcode (ld a,$xx) */
  791.     A += 2;
  792.     rom[A+diff] = rom[A];    /* fix fourth opcode (ld ($xxxx),a */
  793.     /* and from here on, opcodes are encrypted */
  794. }
  795.  
  796.  
  797.  
  798. GAMEX( 1984, kchamp,   0,      kchamp, kchamp,     0,        ROT90, "Data East USA", "Karate Champ (US)", GAME_NO_COCKTAIL )
  799. GAMEX( 1984, karatedo, kchamp, kchamp, kchamp,     0,        ROT90, "Data East Corporation", "Karate Dou (Japan)", GAME_NO_COCKTAIL )
  800. GAMEX( 1984, kchampvs, kchamp, kchampvs, kchampvs, kchampvs, ROT90, "Data East USA", "Karate Champ (US VS version)", GAME_NO_COCKTAIL )
  801. GAMEX( 1984, karatevs, kchamp, kchampvs, kchampvs, kchampvs, ROT90, "Data East Corporation", "Taisen Karate Dou (Japan VS version)", GAME_NO_COCKTAIL )
  802.